package edu.java.homework.hw11.join.solution.dish;

public class Dish {

	// --- Instance Variables --------------------------------------------------
	private String name = null;

	// --- Constructors --------------------------------------------------------
	public Dish(String name) {
		this.name = name;
	}

	// --- Getters and Setters -------------------------------------------------

	public String getName() {
		return name;
	}

	// --- Methods -------------------------------------------------------------

	public synchronized void prepareDish() {
		System.out.println(Thread.currentThread().getName() + " prepares the "
				+ getName() + " .");
	}

	public synchronized void serveDish(Thread joinThread) {
		try {
			joinThread.join();
		} catch (InterruptedException e) {
			System.out.println("Interrupted Exception in thread: "
					+ Thread.currentThread().getName()
					+ ", Reason: join() method.");
		}
		System.out.println(Thread.currentThread().getName() + " serves the "
				+ getName() + " .");
	}

	public synchronized void eatDish(Thread joinThread) {
		try {
			joinThread.join();
		} catch (InterruptedException e) {
			System.out.println("Interrupted Exception in thread: "
					+ Thread.currentThread().getName()
					+ ", Reason: join() method.");
		}
		System.out.println(Thread.currentThread().getName() + " eats the "
				+ getName() + " and sets free the plate. ");

	}
}
